<template>
  <div id="main">
    <div class="one">
      <div class="two">
        <img src="https://img01.yzcdn.cn/vant/cat.jpeg" alt="" />
        <span>{{ nick }}</span>
      </div>
    </div>
    <div class="three">
      <van-cell title="编辑收货地址" is-link @click="ToAddress()" />
    </div>
    <div class="three">
      <van-cell title="查看订单" is-link @click="ToOrder()" />
    </div>
    <div>
      <button type="button" @click="go">
        <span>{{ content }}</span>
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { useRouter, useRoute } from "vue-router";

let nick = ref(localStorage.getItem("nick") || "翠花");
let content = ref(localStorage.getItem("loginStatus") || "退出登录");
const router = useRouter();
const route = useRoute();
watch(
  () => route.query.nick,
  (newNick) => {
    if (newNick && !localStorage.getItem("nick")) {
      nick.value = newNick as string;
    }
  },
  { immediate: true }
);

const go = () => {
  if (content.value === "退出登录") {
    content.value = "登录";
    nick.value = "游客";
    localStorage.setItem("loginStatus", "登录");
    localStorage.setItem("nick", "游客");
  } else {
    content.value = "退出登录";
    nick.value = "翠花";
    localStorage.setItem("loginStatus", "退出登录");
    localStorage.setItem("nick", "翠花");
    router.push("/login");
  }
};
function ToAddress() {
  router.push("/address");
}
function ToOrder() {
  router.push("/ordel");
}
</script>

<style scoped>
#main {
  background-color: #efefef;
  height: 100vh;
  width: 100%;
}
.one {
  background-image: linear-gradient(to bottom, #008705, #00f753);
  width: 100%;
  height: 200px;
}
.one .two {
  position: relative;
}
.one .two img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 50px 10px;
}
.one .two span {
  text-align: center;
  position: absolute;
  top: 80px;
  left: 95px;
}
.three {
  background-color: #ffffff;
}
button {
  border-radius: 8px;
  border: none;
  padding: 10px;
  background-color: #ffffff;
  margin: 40px 140px;
  cursor: pointer;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}
button span {
  font-size: 12px;
}
</style>
